package com.iking.toolkit.model;

import java.io.Serializable;
import java.util.List;

/**
 * 分页对象
 *
 * @author tjw
 * @date 2018年2月3日 下午12:00:04
 */
public class PageRes<T> implements Serializable {

    private static final long serialVersionUID = -485281064667946990L;

    private int PageCurrent;    // 当前页

    private int itemTotal;        // 总条数

    private int PageSize;        // 分页大小

    private int PageCount;        // 总页数

    private int startIndex;        // 起始行

    private List<T> items;        // 查询数据

    public PageRes() {
        super();
    }

    public PageRes(int PageCurrent, int PageSize, int itemTotal, List<T> items) {
        setPageCurrent(PageCurrent);
        setPageSize(PageSize);
        setItemTotal(itemTotal);
        this.items = items;
    }

    public int getPageCurrent() {
        return PageCurrent;
    }


    public void setPageCurrent(int PageCurrent) {
        this.PageCurrent = PageCurrent;
        setStartIndex();
    }

    public int getItemTotal() {
        return itemTotal;
    }

    public void setItemTotal(int itemTotal) {
        this.itemTotal = itemTotal;
        this.PageCount = this.itemTotal % this.PageSize == 0 ? this.itemTotal / this.PageSize
                : this.itemTotal / this.PageSize + 1;
    }

    public int getPageSize() {
        return PageSize;
    }

    public void setPageSize(int PageSize) {
        this.PageSize = PageSize;
        setStartIndex();
    }

    public int getPageCount() {
        return PageCount;
    }

    public void setPageCount(int PageCount) {
        this.PageCount = PageCount;
    }

    public List<T> getItems() {
        return items;
    }

    public void setItems(List<T> items) {
        this.items = items;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex() {
        if (this.PageCurrent != 0 && this.PageSize != 0) {
            this.startIndex = (this.PageCurrent - 1) * this.PageSize;
        } else {
            this.startIndex = 0;
        }
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    @Override
    public String toString() {
        return "PageRes [PageCurrent=" + PageCurrent + ", itemTotal=" + itemTotal + ", PageSize=" + PageSize
                + ", PageCount=" + PageCount + ", startIndex=" + startIndex + ", items=" + items + "]";
    }

}
